#!/usr/bin/perl
# index.cgi

# load modules
require './netebbms-lib.pl';


# read argument in %in
&ReadParse();


# check  netebbms program
foreach $p ( [ $config{'netebbms'}, 'index_netebbms_emsg', 'index_netebbms' ] ) {

	if (!-x $p->[0]) {
		&ui_print_header(undef, $text{'index_title'}, '', undef, 1, 1, 0);

		print &text($p->[1], "<tt>$p->[0]</tt>", "$gconfig{'webprefix'}/config.cgi?$module_name");
 
		&foreign_require("software", "software-lib.pl");
		print '<p>', &software::missing_install_link("netebbms", $text{$p->[2]}, "../$module_name/", $text{'index_title'}), '</p>';
 
		&ui_print_footer("/", $text{'index'});
		exit;
	}
}


# check config/script file
foreach $p ( [ $config{'netebbms_conf'}, 'index_netebbmsconf_emsg' ],
	[ $config{'model_list'}, 'index_modellist_emsg' ] ) {

	if (!-r $p->[0]) {
		&ui_print_header(undef, $text{'index_title'}, '', undef, 1, 1, 0);

		print '<p>', &text($p->[1], "<tt>$p->[0]</tt>", "$gconfig{'webprefix'}/config.cgi?$module_name"), '</p>';
 
		&ui_print_footer("/", $text{'index'});
		exit;
	}
}


# show header
&ui_print_header(undef, $text{'index_title'}, '', undef, 1, 1);


# function table
print &ui_subheading($text{'index_functiontitle'});

my @functions = (
	[ 'animation/index.cgi', $text{'animation_title'}, 'images/animation.gif' ],
	[ 'rssreader/index.cgi', $text{'rssreader_title'}, 'images/rssreader.gif' ],
	[ 'twitterbot/index.cgi', $text{'twitterbot_title'}, 'images/twitterbot.gif' ],
	[ 'twitterclient/index.cgi', $text{'twitterclient_title'}, 'images/twitterclient.gif' ],
);

my @links = ( );
my @titles = ( );
my @icons = ( );

foreach my $item_ref ( @functions ) {
	push(@links, $item_ref->[0]);
	push(@titles, $item_ref->[1]);
	push(@icons, $item_ref->[2]);
}

&icons_table(\@links, \@titles, \@icons, 4);


# daemon control button
if ($access{'apply'}) {
	print &ui_hr();
	print &ui_buttons_start();

	$isrun = &is_netebbms_running();
	if ($isrun == 0) {
		# start button
		print &ui_buttons_row("start.cgi", $text{'index_start'}, $text{'index_startmsg'});

	} elsif ($isrun == 1) {
		# restart / stop buttons
		print &ui_buttons_row("restart.cgi", $text{'index_restart'}, $text{'index_restartmsg'} . $text{'index_restartmsg2'});
		print &ui_buttons_row("stop.cgi", $text{'index_stop'}, $text{'index_stopmsg'});
	}

	print &ui_buttons_end();
}


#----------------------------------------------------

#&show_variable();

#----------------------------------------------------


# show footer
&ui_print_footer('/', $text{'index'});

